﻿using shenghua.Commodity.Commodities;
using shenghua.Common.CustomValueType;
using shenghua.Marketing.SalesPromotions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Commodity.Commodities
{
    /// <summary>
    /// 结合了会员、活动、折扣设置的商品
    /// </summary>
    public class RealCommodity
    {
        public Member.Members.Member Member { get; set; }
        public Commodities.Commodity Commodity { get; set; }
        public CommodityShoppingOption CommodityShoppingOption { get; set; }
        public SalesPromotion SalesPromotion { get; set; }

        public int CommodityId { get; set; }
        public string CommodityName { get; set; }
        public int? ShoppingOptionId { get; set; }
        public bool Shelved { get; set; }
        public bool IsRecommended { get; set; }
        public bool IsEnabledShoppingOption { get; set; }
        public bool HasSalesPromotion { get; set; }
        public string PromotionName
        {
            get
            {
                return HasSalesPromotion ? SalesPromotion.Name: null;
            }
        }
        public DateTime? PromotionEndTime => HasSalesPromotion ? (DateTime?)SalesPromotion.EndTime : null;
        public bool IsForMember { get; set; }
        public long MemberId { get; set; }
        public bool IsCollected { get; set; }
        public Money Price
        {
            get
            {
                return HasSalesPromotion ? PromotionPrice : DiscountPrice;
            }
        }
        public Money MaxPrice
        {
            get
            {
                return Commodity.ShoppingInfo.MaxPrice;
            }
        }
        public Money MinPrice
        {
            get
            {
                return Commodity.ShoppingInfo.MinPrice;
            }
        }
        public bool Discountable { get; set; }
        public Money DiscountPrice
        {
            get
            {
                return OriginalPrice * Discount;
            }
        }
        public double Discount { get; set; }
        public Money PromotionPrice { get; set; }
        public Money OriginalPrice { get; set; }
        public int XPValue { get; set; }
        public int Inventory { get; set; }
        public int MinLimitCount { get; set; }
        public int MaxLimitCount { get; set; }
        public string Picture { get; set; }
        public List<string> Pictures { get; set; }
        public Dictionary<string, string> ShoppingOptionParameters { get; set; }

        public RealCommodity()
        {
            ShoppingOptionParameters = new Dictionary<string, string>();
            Discount = 1;
            OriginalPrice = new Money();
            PromotionPrice = new Money();
            Pictures = new List<string>();

        }

        public bool IsValidCount(int count)
        {
            if (count >= MinLimitCount && count <= MaxLimitCount)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
